package com.usernet.product.json;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

public class JSONUtils {
	private JSONUtils() {
	}

	private static JsonConfig cfg = new JsonConfig();
	/*
	 * 
	 */
	static {
		cfg.registerJsonValueProcessor(java.util.Date.class,
				new JSONValueProcessorImpl());
		cfg.registerJsonValueProcessor(java.sql.Date.class,
				new JSONValueProcessorImpl());
	}

	/*
	 * 
	 */
	public static String toJsonString(Object object, int jsonType) {
		String ret = "";
		switch (jsonType) {
		case JSONTYPE.LISTORARRAY:
			ret = JSONArray.fromObject(object, cfg).toString();
			break;
		case JSONTYPE.OBJECTORBEAN:
			ret = JSONObject.fromObject(object, cfg).toString();
			break;
		}
		return ret;
	}
}
